Jade.EmployeeGridPanel = function( conf ){
	Ext.apply( this, conf );
	var self = this ;
	
	this.operations = new Ufida.grid.handleLink( [{
		key:'edit',
		value : '编辑',
		handler : function() {
			self.doEdit();
		}
	}, {
		key:'remove',
		value : '删除',
		handler : function() {
			self.doDelete();
		}
	} ], {
		width : 100
	});
	
	this.store = new Ext.data.Store({
		url : '/base/employee.do?method=list',
		baseParams : {limit:15},
		autoLoad : false,
		reader : Jade.data.Readers.employeeReader
	});
	
	this.sm = new Ext.grid.CheckboxSelectionModel({singleSelect:false});
	
	this.cm = new Ext.grid.ColumnModel([this.sm,this.operations, {
		header : "员工编号",
		dataIndex : 'code',
		align : 'left'
	}, {
		header : "员工姓名",
		dataIndex : 'name',
		align : 'left'
	}, {
		header : "部门",
		dataIndex : 'department',
		align : 'left'
	}, {
		header : "职务",
		dataIndex : 'job',
		align : 'left'
	}, {
		header : "电话",
		dataIndex : 'phoneNo',
		align : 'left'
	}, {
		header : "手机号",
		dataIndex : 'mobileNo',
		align : 'left'
	}]);
	
	this.cm.defaultSortable = true;
	
	Jade.EmployeeGridPanel.superclass.constructor.call( this , {
		width : 999,
		ds : this.store,
		cm : this.cm,
		sm : this.sm,
		plugins:this.operations,
		loadMask : true,
		viewConfig : {	forceFit : true	},
		tbar : new Ext.Toolbar( {
			style : 'background:#FFFFFF; padding-bottom:5px;',
			items : [ {
				id : 'add',
				text : '新增',
				pressed : true,
				handler : function() {
					self.fireEvent('add');
				}
			}, {
				xtype : 'tbfill'
			}, '员工姓名:', {
				xtype : 'tbspacer'
			}, {
				xtype : 'tbspacer'
			}, self.queryName = new Ext.form.TextField(), {
				xtype : 'tbspacer'
			}, new Ext.Button( {
				text : '开始查询',
				pressed : true,
				handler : function() {
					self.store.baseParams={};
					self.store.baseParams.name = self.queryName.getValue().trim();
					self.store.load();
				}
			})]
		}),
		bbar : new Ext.PagingToolbarExt( {
			id : 'provider',
			cm : this.cm,
			store : this.store,
			pageSize : 15,
			displayInfo : true,
			beforePageText : '当前页数 ',
			afterPageText : '共 {0} 页',
			displayMsg : '显示记录 {0} - {1} 共 {2}',
			emptyMsg : "没有相关数据",
			cls : 'u-toolbar-b'
		})
	});
	
	//编辑
	this.doEdit = function(){
		var record = self.getSelectionModel().getSelected() ;
		self.fireEvent('edit', record);
	};
	
	this.doDelete = function(){
		var record = self.getSelectionModel().getSelected();
		var id = record.get("id");
		Ext.MessageBox.confirm('提示', '确认删除该记录吗？', function(btn) {
			if(btn == 'yes'){
				this._doDelete(id);
			}
		},this);
	};
	
	this._doDelete = function(id){
		Ext.Ajax.request({
			url : '/base/employee.do?method=remove&id=' + id,
			success : function(result, request) {
				messageloaded('删除成功!');
				self.store.reload();
			},
			failure : function(result, request) {
				displayMessageBox('提示', '删除失败!');
			}
		});
	};
	
	// load
	this.load = function( params ){
		self.store.baseParams = params || {};
		self.store.load();
	};
	
	this.addEvents('add','edit');
};

Ext.extend( Jade.EmployeeGridPanel, Ext.grid.GridPanel, {});
